home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / batchut / bathints.zip / BH_08.DOC < prev    next >
Text File  |  1988-04-17  |  10KB  |  278 lines

  1.  
  2.                                   BAT-HINT # 8
  3.  
  4. **************************************************************************
  5.  
  6.     from the BATHINTS library... part of the BATPOWER CONFERENCE from:
  7.  
  8.   THE PAINFRAME OPUS/FIDO 261/1004            LYNX OPUS/FIDO 134/27         
  9.                                       &  
  10.   Baltimore, Maryland (301) 488-7461      Cochrane, Alberta (403) 932-2750
  11.  
  12. **************************************************************************
  13.  
  14.                             ANSI.SYS COMMAND EXAMPLES
  15.  
  16. This BAT-HINT is comprised of an assortment of ANSI.SYS command examples,
  17. and assumes that the user has read BAT-HINT #7 (ANSI.SYS ESCAPE SEQUENCES).
  18. Please recall that you must install the ANSI.SYS device driver in your
  19. config.sys file (and reboot) in order to use ANSI.SYS commands.
  20.  
  21.  
  22. CURSOR CONTROL
  23. --------------
  24.  
  25. The cursor may be easily controlled in batch files using ANSI.SYS commands. 
  26. Carefull manipulation of the cursor can provide a means whereby text may be
  27. displayed at any location on the screen.  A simple example of this control
  28. is shown below:
  29.  
  30.    center1.bat
  31.  
  32.    echo off
  33.    cls
  34.    ESC[12;36H--CENTER--
  35.  
  36. Center1.bat moves the cursor to row 12 column 36 and displays the text      
  37. --CENTER-- in the middle of the screen.  Simple enough.  Now let's modify
  38. this batch file to display not only --CENTER-- in the middle of the screen,
  39. but also the words TOP and BOTTOM at their appropriate locations...
  40.  
  41.    center2.bat
  42.  
  43.    echo off
  44.    cls
  45.    ESC[12;36H--CENTER--ESC[;36H---TOP----ESC[24;36H--BOTTOM--
  46.  
  47. Note how more than one ANSI.SYS command may be placed on a single line so
  48. long as each command is preceeded by an escape character and a left square
  49. bracket.  Note also that to position the cursor in row 1 the number 1 was
  50. not necessary... only the semicolon to indicate that the number to follow is
  51. a column designation.  The ESC[#;#H command actually allows the row # range
  52. to be 1-25.  A further point to note is that it was not necessary in
  53. center2.bat to display the lines in descending order... the center line
  54. appeared first, then the top line and finally the bottom line.  Thus by such
  55. technique it is possible to display text anywhere in the screen at any time. 
  56. For example, using the utility KEY.COM which waits for the user to hit a key
  57. (and optionally returns an errorlevel code equal to the ASCII DEC code of
  58. that key), it is possible to "time" the display of text anywhere on the
  59. screen, as shown in the next example:
  60.  
  61.    center3.bat
  62.  
  63.    echo off
  64.    cls
  65.    ESC[12;36H--CENTER--
  66.    key
  67.    ESC[;36H---TOP----
  68.    key
  69.    ESC[24;36H--BOTTOM--
  70.    key
  71.  
  72. The KEY.COM utility is available in the BATPOWER file area.
  73.  
  74. The next example incorporates the features of center3.bat and introduces
  75. the use of the save cursor command (ESC[s), the erase to end of line command
  76. (ESC[K) and the restore cursor position command (ESC[u)...
  77.  
  78.    center4.bat
  79.  
  80.    echo off
  81.    cls
  82.    ESC[12;36H--CENTER--ESC[s
  83.    key
  84.    ESC[;36H---TOP----
  85.    key
  86.    ESC[24;36H--BOTTOM--
  87.    key
  88.    ESC[uESC[K--center--ESC[25;1H
  89.    key
  90.  
  91. Center4.bat saves the cursor position of the text --CENTER-- ...before the
  92. text is displayed... and later restores that position, erases line 12 from
  93. column 36 to the end of the line, then displays the same text in lower case
  94. and finally moves the cursor to the last line (#25) in column 1 so that the
  95. prompt does not reappear in the midst of the display.
  96.  
  97. Similar cursor movement may be commanded using the move right, left, up and
  98. down ANSI.SYS commands.
  99.  
  100.  
  101. DISPLAY ATTRIBUTES
  102. ------------------
  103.  
  104. The text displayed by the batch file examples shown above may be changed to
  105. high intensity (bold), blinking, reverse video, underlined and even made
  106. invisible using the set attribute ANSI.SYS command (ESC[#m).  The following
  107. example demonstrates the use of these commands:
  108.  
  109.    display1.bat
  110.  
  111.    echo off
  112.    cls
  113.    echo normal
  114.    echo ESC[1mhigh intensityESC[m
  115.    echo ESC[4munderlinedESC[m
  116.    echo ESC[5mblinkingESC[m
  117.    echo ESC[7mreverseESC[m
  118.    echo ESC[8minvisibleESC[m
  119.  
  120. Note that each attribute must be turned off after it is turned on, using the
  121. ESC[m command.  An easier way to accomplish this is to incorporate the "turn
  122. off" attribute command in the next command line, as shown below:
  123.  
  124.    display2.bat
  125.  
  126.    echo off
  127.    cls
  128.    echo normal
  129.    echo ESC[1mhigh intensity
  130.    echo ESC[0;4munderlined
  131.    echo ESC[0;5mblinking
  132.    echo ESC[0;7mreverse
  133.    echo ESC[0;8minvisibleESC[m
  134.  
  135. In a similar manner, several attributes may be turned on and off in a single
  136. ANSI.SYS command, as shown below:
  137.  
  138.    display4.bat
  139.  
  140.    echo off
  141.    cls
  142.    echo normal
  143.    echo ESC[1mhigh intensity
  144.    echo ESC[4mhigh intensity & underlined
  145.    echo ESC[5mhigh intensity & underlined & blinking
  146.    echo ESC[7mhigh intensity & underlined & blinking & reverseESC[m
  147.  
  148. Note from display4.bat that the attribute is remembered...  so that if the
  149. previous attributes are not turned off, the next attribute specified will
  150. incorporate all prior attributes.  Display4.bat is equivalent to
  151. display5.bat shown below:
  152.  
  153.    display5.bat
  154.  
  155.    echo off
  156.    cls
  157.    echo normal
  158.    echo ESC[1mhigh intensity
  159.    echo ESC[0;1;4mhigh intensity & underlined
  160.    echo ESC[0;1;4;5mhigh intensity & underlined & blinking
  161.    echo ESC[0;1;4;5;7mhigh intensity & underlined & blinking & reverseESC[m
  162.  
  163. Display5.bat differs from display4.bat only in that it manually turns off
  164. all prior attributes (via attribute # 0) then turns the attributes on (it
  165. also takes longer to write!).  One last note... remember to turn off all
  166. attributes before the batch file terminates as these attributes are carried
  167. forward by DOS.
  168.  
  169. In a manner similar to that shown in the display?.bat examples (this is
  170. where I get lazy) you can alter the foreground and background colors of the
  171. displayed text.
  172.  
  173.  
  174. DISPLAY MODE
  175. ------------
  176.  
  177. Let it be known that I accept no responsibility for damage or alteration to
  178. any device attached or within any computer system in which the following
  179. mode?.bat files are executed.  I say this only because I haven't the
  180. foggiest idea if switching modes with ANSI.SYS commands may damage or alter
  181. some video cards or monitors or both.  I simply haven't the resources to
  182. check this out.  The resolution and color capability of your display can be
  183. set with ANSI.SYS commands.  For example, to set your display to monchrome
  184. and 25 rows by 40 columns (wide) display and echo the text string HELLO in
  185. the middle of the screen (and then return to normal color mode), you could
  186. use the following batch file:
  187.  
  188.    mode1.bat
  189.  
  190.    echo off
  191.    cls
  192.    echo ESC[0h
  193.    echo ESC[12;18HHELLO
  194.    key
  195.    echo ESC[3h
  196.  
  197. Note that when an ANSI.SYS mode command is issued, the display blanks...
  198. this is the reason the batch file is paused with the KEY command, otherwise
  199. when the mode is returned to normal color by the last line of the batch file
  200. the display will be blanked, resulting in nothing more than a couple of
  201. display skrinks ("skrink" is a term I use to describe the monitor state
  202. during a mode switch and the high-pitched noise that ensues!).  Once again,
  203. other modes may be set in a similar manner with the appropriate code number.
  204.  
  205.  
  206. KEY DEFINITIONS
  207. ---------------
  208.  
  209. The redefinition of keys on the keyboard is a relatively simple matter with
  210. ANSI.SYS commands, and although such commands are not as easy to issue as
  211. those of such programs as SUPERKEY, they are almost as powerfull and a lot
  212. cheaper.  For example, to redefine the key for the letter "a" to the letter
  213. "b" (heaven only knows why you would want to do this!) you could create the
  214. following batch file:
  215.  
  216.    key1.bat
  217.  
  218.    echo off
  219.    cls
  220.    echo ESC[97;98p
  221.  
  222. where 97 is the ASCII DEC code for the character "a" and 98 is the code for
  223. the character "b".  OK, now how to get it back to normal?... like this:
  224.  
  225.    key2.bat
  226.  
  227.    echo off
  228.    cls
  229.    echo ESC[97;97p
  230.  
  231. To redefine a key that was previously altered, just define it to the value
  232. it was originally.  Most people prefer to define keys that are not keys used
  233. frequently...